package com.spddr.pmos.jpa;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import cn.seqdata.jpa.AbstractPersistable;

@Entity
@Table(name = "object_metric")
public class ObjectMetric extends AbstractPersistable<ObjectMetricId> {
	private static final long serialVersionUID = 1L;

	private ObjectType objectType;
	private Metric metric;

	public ObjectMetric() {
	}

	public ObjectMetric(int objectType, String metric) {
		setId(new ObjectMetricId(objectType, metric));
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "object_type", nullable = false, insertable = false, updatable = false)
	@JsonSerialize(using = cn.seqdata.jackson.TypeSerializer.IdName.class)
	public ObjectType getObjectType() {
		return this.objectType;
	}

	public void setObjectType(ObjectType objectType) {
		this.objectType = objectType;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "metric", nullable = false, insertable = false, updatable = false)
	@JsonSerialize(using = cn.seqdata.jackson.StringSerializer.IdName.class)
	public Metric getMetric() {
		return this.metric;
	}

	public void setMetric(Metric metric) {
		this.metric = metric;
	}
}
